Option Explicit

'################################################################
' Descriptr
' 列类型枚举--数据处理器
'################################################################

Implements IDFDataTypeHandler

'################################################################
' Field
'################################################################
' 类型
Private fieldDataType As DF_DataType

'################################################################
' Constructor
'################################################################
Private Sub Class_Initialize()
    fieldDataType = DF_DataType.DF_BOOLEAN
End Sub

Private Sub Class_Terminate()
End Sub

'################################################################
' Property
'################################################################
'----------------------------
' 处理器处理的类型
'----------------------------
' 获取当前处理器处理的类型
Public Property Get IDFDataTypeHandler_DataType() As DF_DataType
    IDFDataTypeHandler_DataType = fieldDataType
End Property


'----------------------------
' 是否支持计算方法
'----------------------------
' 是否支持加法运算
Public Property Get IDFDataTypeHandler_SupportAdd() As Boolean
    IDFDataTypeHandler_SupportAdd = False
End Property

' 是否支持减法运算
Public Property Get IDFDataTypeHandler_SupportSubtract() As Boolean
    IDFDataTypeHandler_SupportSubtract = False
End Property

' 是否支持乘法运算
Public Property Get IDFDataTypeHandler_SupportMultiply() As Boolean
    IDFDataTypeHandler_SupportMultiply = False
End Property

' 是否支持除法运算
Public Property Get IDFDataTypeHandler_SupportDivide() As Boolean
    IDFDataTypeHandler_SupportDivide = False
End Property

'----------------------------
' 是否支持聚合运算
'----------------------------
' 是否支持最大值运算
Public Property Get IDFDataTypeHandler_SupportMax() As Boolean
    IDFDataTypeHandler_SupportMax = False
End Property

' 是否支持最小值运算
Public Property Get IDFDataTypeHandler_SupportMin() As Boolean
    IDFDataTypeHandler_SupportMin = False
End Property

'################################################################
' Function
'################################################################
'----------------------------
' 数据初始化
'----------------------------
' 将输入数据进行初始化
'
' 参数预设的转换方式:
'   True, "True", 1 作为 True 使用
'   False, "False", 0, "" 作为 False 使用
'   Empty 仍然作为 Empty
'   其他全部作为 True 使用
'
' @param origin 原始输入数据
' @return 初始化后的数据
Public Function IDFDataTypeHandler_normalize(ByRef origin As Variant) As Variant
    If IsEmpty(origin) = True Then
        IDFDataTypeHandler_normalize = Empty
    ElseIf VarType(origin) = vbBoolean Then
        IDFDataTypeHandler_normalize = origin
    Else
On Error Goto catch:
        Dim temp As String
        temp = UCase(origin & "")
        If temp = "TRUE" Or temp = "1" Then
            IDFDataTypeHandler_normalize = True
        ElseIf temp = "FALSE" Or temp = "0" Or temp = "" Then
            IDFDataTypeHandler_normalize = False
        Else
            ' 其他情况下，只要有数据就默认为 True
            IDFDataTypeHandler_normalize = True
        End If
        Exit Function
catch:
        ' 发生异常时，统一返回 Empty，不抛出异常
        Err.Clear
        IDFDataTypeHandler_normalize = Empty
    End If
End Function

'----------------------------
' 计算方法
'----------------------------

' 将运算数据转换成当前类型的标准计算类型数据
' 如果需要终止计算，应该返回 Empty
'
' @param v 原始计算数据
' @return 当前类型的标准计算类型数据
Public Function IDFDataTypeHandler_normalizeComputeData(ByRef v As Variant) As Variant
    IDFDataTypeHandler_normalizeComputeData = Empty
End Function

' ==============
' 数值直接计算
' ==============
' 对数据进行加法运算
'
' @param origin 原始输入数据
' @param v 运算数据
' @return 计算后的数据
Public Function IDFDataTypeHandler_add(ByRef origin As Variant, ByRef v As Variant) As Variant
    ' boolean 型数据不做处理
    IDFDataTypeHandler_add = origin
End Function

' 对数据进行减法运算
'
' @param origin 原始输入数据
' @param v 运算数据
' @return 计算后的数据
Public Function IDFDataTypeHandler_subtract(ByRef origin As Variant, ByRef v As Variant) As Variant
    IDFDataTypeHandler_subtract = origin
End Function

' 对数据进行乘法运算
'
' @param origin 原始输入数据
' @param v 运算数据
' @return 计算后的数据
Public Function IDFDataTypeHandler_multiply(ByRef origin As Variant, ByRef v As Variant) As Variant
    IDFDataTypeHandler_multiply = origin
End Function

' 对数据进行除法运算
'
' @param origin 原始输入数据
' @param v 运算数据
' @return 计算后的数据
Public Function IDFDataTypeHandler_divide(ByRef origin As Variant, ByRef v As Variant) As Variant
    IDFDataTypeHandler_divide = origin
End Function

' ==============
' 数组引用计算，并直接修改数组的值
' ==============
' 对数据进行加法运算
' 如果参数 v 是 Empty 将不会进行计算
'
' @param origin 原始数组 (下标从 0 开始)
' @param size 需要进行比较的数据数量
' @param v 运算数据
Public Sub IDFDataTypeHandler_addForArray(ByRef origin As Variant, ByRef size As Long, ByRef v As Variant)
    ' 不支持
End Sub

' 对数据进行减法运算
' 如果参数 v 是 Empty 将不会进行计算
'
' @param origin 原始数组 (下标从 0 开始)
' @param size 需要进行比较的数据数量
' @param v 运算数据
Public Sub IDFDataTypeHandler_subtractForArray(ByRef origin As Variant, ByRef size As Long, ByRef v As Variant)
    ' 不支持
End Sub

' 对数据进行乘法运算
' 如果参数 v 是 Empty 将不会进行计算
'
' @param origin 原始数组 (下标从 0 开始)
' @param size 需要进行比较的数据数量
' @param v 运算数据
Public Sub IDFDataTypeHandler_multiplyForArray(ByRef origin As Variant, ByRef size As Long, ByRef v As Variant)
    ' 不支持
End Sub

' 对数据进行除法运算
' 如果参数 v 是 Empty 将不会进行计算
'
' @param origin 原始数组 (下标从 0 开始)
' @param size 需要进行比较的数据数量
' @param v 运算数据
Public Sub IDFDataTypeHandler_divideForArray(ByRef origin As Variant, ByRef size As Long, ByRef v As Variant)
    ' 不支持
End Sub

'===========
' 和其他 Series 类型做计算
'===========
' 该类型不支持这个计算
'
' @param v 运算数据
Public Sub IDFDataTypeHandler_mergeAdd(ByRef src As IDFSeries, ByRef desc As IDFSeries)
End Sub

' 该类型不支持这个计算
'
' @param v 运算数据
Public Sub IDFDataTypeHandler_mergeSubtract(ByRef src As IDFSeries, ByRef desc As IDFSeries)
End Sub

' 该类型不支持这个计算
'
' @param v 运算数据
Public Sub IDFDataTypeHandler_mergeMultiply(ByRef src As IDFSeries, ByRef desc As IDFSeries)
End Sub

' 该类型不支持这个计算
'
' @param v 运算数据
Public Sub IDFDataTypeHandler_mergeDivide(ByRef src As IDFSeries, ByRef desc As IDFSeries)
End Sub

'----------------------------
' 聚合方法
'----------------------------
' 取全体数据的最大值
'
' @param data 数据集合
' @return 最大值
Public Function IDFDataTypeHandler_max(ByRef data As IDFSeries) As Variant
    IDFDataTypeHandler_max = Empty
End Function

' 取全体数据的最小值
'
' @param data 数据集合
' @return 最小值
Public Function IDFDataTypeHandler_min(ByRef data As IDFSeries) As Variant
    IDFDataTypeHandler_min = Empty
End Function

'================
' 数组引用聚合计算
'================
' 取全体数据的最大值
'
' @param data 数据数组 (下标从 0 开始)
' @param size 需要进行比较的数据数量
' @return 最大值
Public Function IDFDataTypeHandler_maxForArray(ByRef origin As Variant, ByRef size As Long) As Variant
    IDFDataTypeHandler_maxForArray = Empty
End Function

' 取全体数据的最小值
'
' @param data 数据数组 (下标从 0 开始)
' @param size 需要进行比较的数据数量
' @return 最小值
Public Function IDFDataTypeHandler_minForArray(ByRef origin As Variant, ByRef size As Long) As Variant
    IDFDataTypeHandler_minForArray = Empty
End Function

'----------------------------
' 比较运算
'----------------------------
'=========================================
' 对数组引用做比较，并生成 Boolean IDFSeries
'=========================================
' 对数组的每一个元素和指定数据进行比较，返回一个和输入数组长度相同的 Boolean 型的 series
' = 运算
' True = True  = True
' False = False= True
' Empty = Empty= True
' Other        = False
'
' 参数 v 预设的转换方式:
'   True, "True", 1 作为 True 使用
'   False, "False", 0, "" 作为 False 使用
'   Empty 仍然作为 Empty
'   其他全部作为 True 使用
'
' @param origin 需要比较的数组 (下标从 0 开始)
' @param size 需要进行比较的数据数量
' @param v 参与比较的数据
' @return Boolean 型的 series
Public Function IDFDataTypeHandler_eqForArray(ByRef origin As Variant, ByRef size As Long, ByRef v As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=DF_DataType.DF_BOOLEAN
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_eqForArray = innerSeries

    ' 2. 如果 v 是 Empty，则单独进行检查
    Dim i As Long
    If IsEmpty(v) Then
        For i = 0 To size - 1
            result.appendData IsEmpty(origin(i))
        Next

        Exit Function
    End If

    ' 3. 无论 v 是什么内容，将 v 转换成 boolean
    Dim booleanVal As Boolean
    booleanVal = IDFDataTypeHandler_normalize(v)

    ' 4. 遍历数据并比较
    For i = 0 To size - 1
        If IsEmpty(origin(i)) Then
            result.appendData False
        Else
            result.appendData (origin(i) = booleanVal)
        End If
    Next
End Function

' 对数组的每一个元素和指定数据进行比较，返回一个和输入数组长度相同的 Boolean 型的 series
' != 运算
' True = True  = False
' False = False= False
' Empty = Empty= False
' Other        = True
'
' @param origin 需要比较的数组 (下标从 0 开始)
' @param size 需要进行比较的数据数量
' @param v 参与比较的数据
' @return Boolean 型的 series
Public Function IDFDataTypeHandler_neForArray(ByRef origin As Variant, ByRef size As Long, ByRef v As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=DF_DataType.DF_BOOLEAN
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_neForArray = innerSeries

    ' 2. 如果 v 是 Empty，则单独进行检查
    Dim i As Long
    If IsEmpty(v) Then
        For i = 0 To size - 1
            result.appendData (Not IsEmpty(origin(i)))
        Next

        Exit Function
    End If

    ' 3. 无论 v 是什么内容，将 v 转换成 boolean
    Dim booleanVal As Boolean
    booleanVal = IDFDataTypeHandler_normalize(v)

    ' 4. 遍历数据并比较
    For i = 0 To size - 1
        If IsEmpty(origin(i)) Then
            result.appendData False
        Else
            result.appendData (origin(i) <> booleanVal)
        End If
    Next
End Function

' 对数组的每一个元素和指定数据进行比较，返回一个和输入数组长度相同的 Boolean 型的 series
' > 运算
' True > False    = True
' 非Empty > Empty = True
' Empty < 非Empty = False
' Other           = False
'
' @param origin 需要比较的数组 (下标从 0 开始)
' @param size 需要进行比较的数据数量
' @param v 参与比较的数据
' @return Boolean 型的 series
Public Function IDFDataTypeHandler_gtForArray(ByRef origin As Variant, ByRef size As Long, ByRef v As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=DF_DataType.DF_BOOLEAN
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_gtForArray = innerSeries

    ' 2. 如果 v 是 Empty，则单独计算
    Dim i As Long
    If IsEmpty(v) Then
        For i = 0 To size - 1
            ' 非Empty > Empty = True
            result.appendData (Not IsEmpty(origin(i)))
        Next

        Exit Function
    End If

    ' 3. 无论 v 是什么内容，将 v 转换成 boolean
    Dim booleanVal As Boolean
    booleanVal = IDFDataTypeHandler_normalize(v)

    ' 4. 遍历数据并比较
    For i = 0 To size - 1
        If IsEmpty(origin(i)) Then
            result.appendData False
        Else
            result.appendData (origin(i) = True And booleanVal = False)
        End If
    Next
End Function

' 对数组的每一个元素和指定数据进行比较，返回一个和输入数组长度相同的 Boolean 型的 series
' < 运算
' False > True    = True
' Empty < 非Empty = True
' 非Empty > Empty = False
' Other           = False
'
' @param origin 需要比较的数组 (下标从 0 开始)
' @param size 需要进行比较的数据数量
' @param v 参与比较的数据
' @return Boolean 型的 series
Public Function IDFDataTypeHandler_ltForArray(ByRef origin As Variant, ByRef size As Long, ByRef v As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=DF_DataType.DF_BOOLEAN
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_ltForArray = innerSeries

    ' 2. 如果 v 是 Empty，则单独计算
    Dim i As Long
    If IsEmpty(v) Then
        For i = 0 To size - 1
            ' 非Empty > Empty = False
            result.appendData IsEmpty(origin(i))
        Next

        Exit Function
    End If

    ' 3. 无论 v 是什么内容，将 v 转换成 boolean
    Dim booleanVal As Boolean
    booleanVal = IDFDataTypeHandler_normalize(v)

    ' 4. 遍历数据并比较
    For i = 0 To size - 1
        If IsEmpty(origin(i)) Then
            result.appendData True
        Else
            result.appendData (origin(i) = False And booleanVal = True)
        End If
    Next
End Function

' 对数组的每一个元素和指定数据进行比较，返回一个和输入数组长度相同的 Boolean 型的 series
' >= 运算
' True > False = True
' True = True  = True
' False = False= True
' False < True = False
' Empty = Empty= True
' 非Empty> Empty= True
' Empty< 非Empty=False
'
' @param origin 需要比较的数组 (下标从 0 开始)
' @param size 需要进行比较的数据数量
' @param v 参与比较的数据
' @return Boolean 型的 series
Public Function IDFDataTypeHandler_geForArray(ByRef origin As Variant, ByRef size As Long, ByRef v As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=DF_DataType.DF_BOOLEAN
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_geForArray = innerSeries

    ' 2. 如果 v 是 Empty，则单独计算
    Dim i As Long
    If IsEmpty(v) Then
        For i = 0 To size - 1
            ' 非Empty> Empty= True
            ' Empty = Empty= True
            result.appendData True
        Next

        Exit Function
    End If

    ' 3. 无论 v 是什么内容，将 v 转换成 boolean
    Dim booleanVal As Boolean
    booleanVal = IDFDataTypeHandler_normalize(v)

    ' 4. 遍历数据并比较
    For i = 0 To size - 1
        If IsEmpty(origin(i)) Then
            result.appendData False
        ElseIf origin(i) = False And booleanVal = True Then
            ' False < True = False
            result.appendData False
        Else
            result.appendData True
        End If
    Next
End Function

' 对数组的每一个元素和指定数据进行比较，返回一个和输入数组长度相同的 Boolean 型的 series
' <= 运算
' True > False = False
' False < True = True
' True = True  = True
' False = False= True
' Empty = Empty= True
' 非Empty> Empty= False
' Empty< 非Empty= True
'
' @param origin 需要比较的数组 (下标从 0 开始)
' @param size 需要进行比较的数据数量
' @param v 参与比较的数据
' @return Boolean 型的 series
Public Function IDFDataTypeHandler_leForArray(ByRef origin As Variant, ByRef size As Long, ByRef v As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=DF_DataType.DF_BOOLEAN
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_leForArray = innerSeries

    ' 2. 如果 v 是 Empty，则单独计算
    Dim i As Long
    If IsEmpty(v) Then
        For i = 0 To size - 1
            ' Empty = Empty= True
            ' 非Empty> Empty= False
            result.appendData IsEmpty(origin(i))
        Next

        Exit Function
    End If

    ' 3. 无论 v 是什么内容，将 v 转换成 boolean
    Dim booleanVal As Boolean
    booleanVal = IDFDataTypeHandler_normalize(v)

    ' 4. 遍历数据并比较
    For i = 0 To size - 1
        If IsEmpty(origin(i)) Then
            ' Empty< 非Empty= True
            result.appendData True
        ElseIf origin(i) = True And booleanVal = False Then
            ' True > False = False
            result.appendData False
        Else
            result.appendData True
        End If
    Next
End Function

' 对数组的每一个元素和指定数据进行比较，返回一个和输入数组长度相同的 Boolean 型的 series
' in() 运算
'
' True = True  = True
' False = False= True
' Empty = Empty= True
' Other        = False
'
' @param origin 需要比较的数组 (下标从 0 开始)
' @param size 需要进行比较的数据数量
' @param vs 参与比较的数据数组
' @return Boolean 型的 series
Public Function IDFDataTypeHandler_inValsForArray(ByRef origin As Variant, ByRef size As Long, ByRef vs As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=DF_DataType.DF_BOOLEAN
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_inValsForArray = innerSeries

    ' 2. 将所有 vs 转换成 Boolean 或 Empty
    Dim vsMin As Integer
    Dim vsMax As Integer
    vsMin = LBound(vs)
    vsMax = UBound(vs)

    Dim realVs() As Variant
    Dim realVsMax As Integer
    realVsMax = vsMax - vsMin
    ReDim realVs(0 To realVsMax) As Variant

    For i = 0 To realVsMax
        realVs(i) = IDFDataTypeHandler_normalize(vs(vsMin + i))
    Next

    ' 3. 进行比较
    Dim j As Integer
    Dim temp As Variant
    For i = 0 To size - 1
        temp = origin(i)
        If IsEmpty(temp) Then
            ' Empty = Empty= True
            For j = 0 To realVsMax
                If IsEmpty(realVs(i)) Then
                    result.appendData True
                    Exit For
                End If
            Next

            ' 如果没有在 vs 中找到 Empty 数据，则默认设置为 False
            If j > realVsMax Then
                result.appendData False
            End If
        Else
            ' True = True  = True
            ' False = False= True
            For j = 0 To realVsMax
                If temp = realVs(i) Then
                    result.appendData True
                    Exit For
                End If
            Next

            ' 如果没有在 vs 中找相等的数据，则默认设置为 False
            If j > realVsMax Then
                result.appendData False
            End If
        End If
    Next
End Function

' 对数组的每一个元素和指定数据进行比较，返回一个和输入数组长度相同的 Boolean 型的 series
' between 运算
'
' @param origin 需要比较的数组 (下标从 0 开始)
' @param size 需要进行比较的数据数量
' @param left 参与比较的左边界数据
' @param right 参与比较的右边界数据
' @return Boolean 型的 series
Public Function IDFDataTypeHandler_betweenForArray(ByRef origin As Variant, ByRef size As Long, ByRef left As Variant, ByRef right As Variant) As IDFSeries

    ' 1. 将所有左右两值转换成 Boolean 或 Empty
    Dim realLeft As Variant
    Dim realRight As Variant
    realLeft = IDFDataTypeHandler_normalize(left)
    realRight = IDFDataTypeHandler_normalize(right)

    ' 2. 检查左右值的关系
    ' 2.1 left = right, 降级成: [=]运算
    If realLeft = realRight Then
        Set IDFDataTypeHandler_betweenForArray = IDFDataTypeHandler_eqForArray(origin, size, realLeft)
        Exit Function
    End If

    '----------------------------------------------------------
    '----------------------------------------------------------
    '----------------------------------------------------------
    ' 剩余情况需要初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=DF_DataType.DF_BOOLEAN
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_betweenForArray = innerSeries

    ' 2.2 left < right
    '     可能的情况:
    '      empty < False
    '      empty < True
    '      False < True
    Dim i As Long
    If IsEmpty(realLeft) Then
        If realRight = False Then
            ' 2.2.1 empty < False
            ' VVVVV
            ' empty <= elem <= False
            ' VVVVV
            ' elem = Empty Or elem = False ===> True; Other ===> False
            For i = 0 To size - 1
                If IsEmpty(origin(i)) Then
                    result.appendData True
                ElseIf origin(i) = False Then
                    result.appendData True
                Else
                    result.appendData False
                End If
            Next
        Else
            ' 2.2.2 empty < True
            ' VVVVV
            ' empty <= elem <= True
            ' VVVVV
            ' Empty, True, False ===> True; 这种情况下，不存在 False 的情况，全部都是 True
            For i = 0 To size - 1
                result.appendData True
            Next
        End If
    ElseIf realLeft = False And realRight = True Then
        ' 2.2.3 False < True
        ' VVVVV
        ' False <= elem <= True
        ' VVVVV
        ' Empty ==> False; True, False ===> True
        For i = 0 To size - 1
            result.appendData (Not IsEmpty(origin(i)))
        Next
    Else
        ' 2.3 left > right, 全部返回 False
        '     False > Empty
        '     True > Empty
        '     True > False
        For i = 0 To size - 1
            result.appendData False
        Next
    End If

End Function

'=========================================
' 对 Series 的数据做比较，并生成 Boolean IDFSeries
'=========================================
' 对 Series 的每一个元素和指定数据进行比较，返回一个和输入数组长度相同的 Boolean 型的 series
' = 运算
' True = True  = True
' False = False= True
' Empty = Empty= True
' Other        = False
'
' @param origin 需要比较的 Series
' @param v 参与比较的数据
' @return Boolean 型的 series
Public Function IDFDataTypeHandler_eqForSeries(ByRef origin As IDFSeries, ByRef v As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=DF_DataType.DF_BOOLEAN
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_eqForSeries = innerSeries

    ' 2. 如果 v 是 Empty，则单独进行检查
    Dim i As Long
    If IsEmpty(v) Then
        For i = 0 To origin.Size - 1
            result.appendData IsEmpty(origin.unsafeGetData(i))
        Next

        Exit Function
    End If

    ' 3. 无论 v 是什么内容，将 v 转换成 boolean
    Dim booleanVal As Boolean
    booleanVal = IDFDataTypeHandler_normalize(v)

    ' 4. 遍历数据并比较
    Dim temp As Variant
    For i = 0 To origin.Size - 1
        temp = origin.unsafeGetData(i)
        If IsEmpty(temp) Then
            result.appendData False
        Else
            result.appendData (temp = booleanVal)
        End If
    Next
End Function

' 对 Series 的每一个元素和指定数据进行比较，返回一个和输入数组长度相同的 Boolean 型的 series
' != 运算
' True = True  = False
' False = False= False
' Empty = Empty= False
' Other        = True
'
' @param origin 需要比较的 Series
' @param v 参与比较的数据
' @return Boolean 型的 series
Public Function IDFDataTypeHandler_neForSeries(ByRef origin As IDFSeries, ByRef v As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=DF_DataType.DF_BOOLEAN
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_neForSeries = innerSeries

    ' 2. 如果 v 是 Empty，则单独进行检查
    Dim i As Long
    If IsEmpty(v) Then
        For i = 0 To origin.Size - 1
            result.appendData (Not IsEmpty(origin.unsafeGetData(i)))
        Next

        Exit Function
    End If

    ' 3. 无论 v 是什么内容，将 v 转换成 boolean
    Dim booleanVal As Boolean
    booleanVal = IDFDataTypeHandler_normalize(v)

    ' 4. 遍历数据并比较
    Dim temp As Variant
    For i = 0 To origin.Size - 1
        temp = origin.unsafeGetData(i)
        If IsEmpty(temp) Then
            result.appendData False
        Else
            result.appendData (temp <> booleanVal)
        End If
    Next
End Function

' 对 Series 的每一个元素和指定数据进行比较，返回一个和输入数组长度相同的 Boolean 型的 series
' > 运算
' True > False    = True
' 非Empty > Empty = True
' Empty < 非Empty = False
' Other           = False
'
' @param origin 需要比较的 Series
' @param v 参与比较的数据
' @return Boolean 型的 series
Public Function IDFDataTypeHandler_gtForSeries(ByRef origin As IDFSeries, ByRef v As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=DF_DataType.DF_BOOLEAN
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_gtForSeries = innerSeries

    ' 2. 如果 v 是 Empty，则单独计算
    Dim i As Long
    If IsEmpty(v) Then
        For i = 0 To origin.Size - 1
            ' 非Empty > Empty = True
            result.appendData (Not IsEmpty(origin.unsafeGetData(i)))
        Next

        Exit Function
    End If

    ' 3. 无论 v 是什么内容，将 v 转换成 boolean
    Dim booleanVal As Boolean
    booleanVal = IDFDataTypeHandler_normalize(v)

    ' 4. 遍历数据并比较
    Dim temp As Variant
    For i = 0 To origin.Size - 1
        temp = origin.unsafeGetData(i)
        If IsEmpty(temp) Then
            result.appendData False
        Else
            result.appendData (temp = True And booleanVal = False)
        End If
    Next
End Function

' 对 Series 的每一个元素和指定数据进行比较，返回一个和输入数组长度相同的 Boolean 型的 series
' < 运算
' False > True    = True
' Empty < 非Empty = True
' 非Empty > Empty = False
' Other           = False
'
' @param origin 需要比较的 Series
' @param v 参与比较的数据
' @return Boolean 型的 series
Public Function IDFDataTypeHandler_ltForSeries(ByRef origin As IDFSeries, ByRef v As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=DF_DataType.DF_BOOLEAN
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_ltForSeries = innerSeries

    ' 2. 如果 v 是 Empty，则单独计算
    Dim i As Long
    If IsEmpty(v) Then
        For i = 0 To origin.Size - 1
            ' 非Empty > Empty = False
            result.appendData IsEmpty(origin.unsafeGetData(i))
        Next

        Exit Function
    End If

    ' 3. 无论 v 是什么内容，将 v 转换成 boolean
    Dim booleanVal As Boolean
    booleanVal = IDFDataTypeHandler_normalize(v)

    ' 4. 遍历数据并比较
    Dim temp As Variant
    For i = 0 To origin.Size - 1
        temp = origin.unsafeGetData(i)
        If IsEmpty(temp) Then
            result.appendData True
        Else
            result.appendData (temp = False And booleanVal = True)
        End If
    Next
End Function

' 对 Series 的每一个元素和指定数据进行比较，返回一个和输入数组长度相同的 Boolean 型的 series
' >= 运算
' True > False = True
' True = True  = True
' False = False= True
' False < True = False
' Empty = Empty= True
' 非Empty> Empty= True
' Empty< 非Empty=False
'
' @param origin 需要比较的 Series
' @param v 参与比较的数据
' @return Boolean 型的 series
Public Function IDFDataTypeHandler_geForSeries(ByRef origin As IDFSeries, ByRef v As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=DF_DataType.DF_BOOLEAN
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_geForSeries = innerSeries

    ' 2. 如果 v 是 Empty，则单独计算
    Dim i As Long
    If IsEmpty(v) Then
        For i = 0 To origin.Size - 1
            ' 非Empty> Empty= True
            ' Empty = Empty= True
            result.appendData True
        Next

        Exit Function
    End If

    ' 3. 无论 v 是什么内容，将 v 转换成 boolean
    Dim booleanVal As Boolean
    booleanVal = IDFDataTypeHandler_normalize(v)

    ' 4. 遍历数据并比较
    Dim temp As Variant
    For i = 0 To origin.Size - 1
        temp = origin.unsafeGetData(i)
        If IsEmpty(temp) Then
            result.appendData False
        ElseIf temp = False And booleanVal = True Then
            ' False < True = False
            result.appendData False
        Else
            result.appendData True
        End If
    Next
End Function

' 对 Series 的每一个元素和指定数据进行比较，返回一个和输入数组长度相同的 Boolean 型的 series
' <= 运算
' True > False = False
' False < True = True
' True = True  = True
' False = False= True
' Empty = Empty= True
' 非Empty> Empty= False
' Empty< 非Empty= True
'
' @param origin 需要比较的 Series
' @param v 参与比较的数据
' @return Boolean 型的 series
Public Function IDFDataTypeHandler_leForSeries(ByRef origin As IDFSeries, ByRef v As Variant) As IDFSeries
   ' 1. 初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=DF_DataType.DF_BOOLEAN
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_leForSeries = innerSeries

    ' 2. 如果 v 是 Empty，则单独计算
    Dim i As Long
    If IsEmpty(v) Then
        For i = 0 To origin.Size - 1
            ' Empty = Empty= True
            ' 非Empty> Empty= False
            result.appendData IsEmpty(origin.unsafeGetData(i))
        Next

        Exit Function
    End If

    ' 3. 无论 v 是什么内容，将 v 转换成 boolean
    Dim booleanVal As Boolean
    booleanVal = IDFDataTypeHandler_normalize(v)

    ' 4. 遍历数据并比较
    Dim temp As Variant
    For i = 0 To origin.Size - 1
        temp = origin.unsafeGetData(i)
        If IsEmpty(temp) Then
            ' Empty< 非Empty= True
            result.appendData True
        ElseIf temp = True And booleanVal = False Then
            ' True > False = False
            result.appendData False
        Else
            result.appendData True
        End If
    Next
End Function

' 对 Series 的每一个元素和指定数据进行比较，返回一个和输入数组长度相同的 Boolean 型的 series
' in() 运算
'
' True = True  = True
' False = False= True
' Empty = Empty= True
' Other        = False
'
' @param origin 需要比较的 Series
' @param vs 参与比较的数据数组
' @return Boolean 型的 series
Public Function IDFDataTypeHandler_inValsForSeries(ByRef origin As IDFSeries, ByRef vs As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=DF_DataType.DF_BOOLEAN
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_inValsForSeries = innerSeries

    ' 2. 将所有 vs 转换成 Boolean 或 Empty
    Dim vsMin As Integer
    Dim vsMax As Integer
    vsMin = LBound(vs)
    vsMax = UBound(vs)

    Dim realVs() As Variant
    Dim realVsMax As Integer
    realVsMax = vsMax - vsMin
    ReDim realVs(0 To realVsMax) As Variant

    For i = 0 To realVsMax
        realVs(i) = IDFDataTypeHandler_normalize(vs(vsMin + i))
    Next

    ' 3. 进行比较
    Dim j As Integer
    Dim temp As Variant
    For i = 0 To origin.Size - 1
        temp = origin.unsafeGetData(i)
        If IsEmpty(temp) Then
            ' Empty = Empty= True
            For j = 0 To realVsMax
                If IsEmpty(realVs(i)) Then
                    result.appendData True
                    Exit For
                End If
            Next

            ' 如果没有在 vs 中找到 Empty 数据，则默认设置为 False
            If j > realVsMax Then
                result.appendData False
            End If
        Else
            ' True = True  = True
            ' False = False= True
            For j = 0 To realVsMax
                If temp = realVs(i) Then
                    result.appendData True
                    Exit For
                End If
            Next

            ' 如果没有在 vs 中找相等的数据，则默认设置为 False
            If j > realVsMax Then
                result.appendData False
            End If
        End If
    Next
End Function

' 对 Series 的每一个元素和指定数据进行比较，返回一个和输入数组长度相同的 Boolean 型的 series
' between 运算
'
' @param origin 需要比较的 Series
' @param left 参与比较的左边界数据
' @param right 参与比较的右边界数据
' @return Boolean 型的 series
Public Function IDFDataTypeHandler_betweenForSeries(ByRef origin As IDFSeries, ByRef left As Variant, ByRef right As Variant) As IDFSeries

    ' 1. 将所有左右两值转换成 Boolean 或 Empty
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=DF_DataType.DF_BOOLEAN
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_betweenForSeries = innerSeries

    ' 2. 检查左右值的关系
    ' 2.1 left = right, 降级成: [=]运算
    If realLeft = realRight Then
        Set IDFDataTypeHandler_betweenForSeries = IDFDataTypeHandler_eqForSeries(origin, realLeft)
        Exit Function
    End If

    '----------------------------------------------------------
    '----------------------------------------------------------
    '----------------------------------------------------------
    ' 剩余情况需要初始化结果对象
    Dim result As DFSeriesInner
    Set result = New DFSeriesInner
    result.Init dType:=DF_DataType.DF_BOOLEAN
    Set IDFDataTypeHandler_betweenForSeries = result

    ' 2.2 left < right
    '     可能的情况:
    '      empty < False
    '      empty < True
    '      False < True
    Dim i As Long
    Dim temp As Variant
    If IsEmpty(realLeft) Then
        If realRight = False Then
            ' 2.2.1 empty < False
            ' VVVVV
            ' empty <= elem <= False
            ' VVVVV
            ' elem = Empty Or elem = False ===> True; Other ===> False
            For i = 0 To origin.Size - 1
                temp = origin.unsafeGetData(i)
                If IsEmpty(temp) Then
                    result.appendData True
                ElseIf temp = False Then
                    result.appendData True
                Else
                    result.appendData False
                End If
            Next
        Else
            ' 2.2.2 empty < True
            ' VVVVV
            ' empty <= elem <= True
            ' VVVVV
            ' Empty, True, False ===> True; 这种情况下，不存在 False 的情况，全部都是 True
            For i = 0 To origin.Size - 1
                result.appendData True
            Next
        End If
    ElseIf realLeft = False And realRight = True Then
        ' 2.2.3 False < True
        ' VVVVV
        ' False <= elem <= True
        ' VVVVV
        ' Empty ==> False; True, False ===> True
        For i = 0 To origin.Size - 1
            result.appendData (Not IsEmpty(origin.unsafeGetData(i)))
        Next
    Else
        ' 2.3 left > right, 全部返回 False
        '     False > Empty
        '     True > Empty
        '     True > False
        For i = 0 To origin.Size - 1
            result.appendData False
        Next
    End If

End Function


'=========================================
' 对数组引用做比较，并生成 IDFSeries 来保存结果为 true 的 数据
'=========================================
' 对数组的每一个元素和指定数据进行比较，返回一个同类型的 series，来保存比较结果为 true 的 数据
' = 运算
' True = True  = True
' False = False= True
' Empty = Empty= True
' Other        = False
'
' @param origin 需要比较的数组 (下标从 0 开始)
' @param size 需要进行比较的数据数量
' @param v 参与比较的数据
' @return IDFSeries 来保存比较结果为 true 的 数据
Public Function IDFDataTypeHandler_eqToSeriesForArray(ByRef origin As Variant, ByRef size As Long, ByRef v As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=DF_DataType.DF_BOOLEAN
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_eqToSeriesForArray = innerSeries

    ' 2. 如果 v 是 Empty，则单独进行检查
    Dim i As Long
    If IsEmpty(v) Then
        For i = 0 To size - 1
            If IsEmpty(origin(i)) Then
                result.appendEmpty
            End If
        Next

        Exit Function
    End If

    ' 3. 无论 v 是什么内容，将 v 转换成 boolean
    Dim booleanVal As Boolean
    booleanVal = IDFDataTypeHandler_normalize(v)

    ' 4. 遍历数据并比较
    Dim temp As Variant
    For i = 0 To size - 1
        temp = origin(i)
        If temp = booleanVal Then
            result.appendData temp
        End If
    Next
End Function

' 对数组的每一个元素和指定数据进行比较，返回一个同类型的 series，来保存比较结果为 true 的 数据
' != 运算
' True = True  = False
' False = False= False
' Empty = Empty= False
' Other        = True
'
' @param origin 需要比较的数组 (下标从 0 开始)
' @param size 需要进行比较的数据数量
' @param v 参与比较的数据
' @return IDFSeries 来保存比较结果为 true 的 数据
Public Function IDFDataTypeHandler_neToSeriesForArray(ByRef origin As Variant, ByRef size As Long, ByRef v As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=DF_DataType.DF_BOOLEAN
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_neToSeriesForArray = innerSeries

    ' 2. 如果 v 是 Empty，则单独进行检查
    Dim i As Long
    Dim temp As Variant
    If IsEmpty(v) Then
        For i = 0 To size - 1
            temp = origin(i)
            If Not IsEmpty(temp) Then
                result.appendData temp
            End If
        Next

        Exit Function
    End If

    ' 3. 无论 v 是什么内容，将 v 转换成 boolean
    Dim booleanVal As Boolean
    booleanVal = IDFDataTypeHandler_normalize(v)

    ' 4. 遍历数据并比较
    For i = 0 To size - 1
        temp = origin(i)
        If temp <> booleanVal Then
            result.appendData temp
        End If
    Next
End Function

' 对数组的每一个元素和指定数据进行比较，返回一个同类型的 series，来保存比较结果为 true 的 数据
' > 运算
' True > False    = True
' 非Empty > Empty = True
' Empty < 非Empty = False
' Other           = False
'
' @param origin 需要比较的数组 (下标从 0 开始)
' @param size 需要进行比较的数据数量
' @param v 参与比较的数据
' @return IDFSeries 来保存比较结果为 true 的 数据
Public Function IDFDataTypeHandler_gtToSeriesForArray(ByRef origin As Variant, ByRef size As Long, ByRef v As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=DF_DataType.DF_BOOLEAN
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_gtToSeriesForArray = innerSeries

    ' 2. 如果 v 是 Empty，则单独计算
    Dim i As Long
    Dim temp As Variant
    If IsEmpty(v) Then
        For i = 0 To size - 1
            temp = origin(i)
            ' 非Empty > Empty = True
            If Not IsEmpty(temp) Then
                result.appendData temp
            End If
        Next

        Exit Function
    End If

    ' 3. 无论 v 是什么内容，将 v 转换成 boolean
    Dim booleanVal As Boolean
    booleanVal = IDFDataTypeHandler_normalize(v)

    ' 4. 遍历数据并比较
    ' True > False    = True
    If booleanVal = False Then
        For i = 0 To size - 1
            temp = origin(i)
            If temp = True Then
                result.appendData temp
            End If
        Next
    End If
    ' booleanVal = True 不作处理，返回空数据对象
End Function

' 对数组的每一个元素和指定数据进行比较，返回一个同类型的 series，来保存比较结果为 true 的 数据
' < 运算
' False > True    = True
' Empty < 非Empty = True
' 非Empty > Empty = False
' Other           = False
'
' @param origin 需要比较的数组 (下标从 0 开始)
' @param size 需要进行比较的数据数量
' @param v 参与比较的数据
' @return IDFSeries 来保存比较结果为 true 的 数据
Public Function IDFDataTypeHandler_ltToSeriesForArray(ByRef origin As Variant, ByRef size As Long, ByRef v As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=DF_DataType.DF_BOOLEAN
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_ltToSeriesForArray = innerSeries

    ' 2. 如果 v 是 Empty，则单独计算
    Dim i As Long
    If IsEmpty(v) Then
        ' 如果 v 是 Empty，则无法找到符合的数据，返回空数据对象
        Exit Function
    End If

    ' 3. 无论 v 是什么内容，将 v 转换成 boolean
    Dim booleanVal As Boolean
    booleanVal = IDFDataTypeHandler_normalize(v)

    ' 4. 遍历数据并比较
    Dim temp As Variant
    For i = 0 To size - 1
        temp = origin(i)
        If IsEmpty(temp) Then
            result.appendEmpty
        ElseIf temp = False And booleanVal = True Then
            result.appendData temp
        End If
    Next
End Function

' 对数组的每一个元素和指定数据进行比较，返回一个同类型的 series，来保存比较结果为 true 的 数据
' >= 运算
' True > False = True
' True = True  = True
' False = False= True
' False < True = False
' Empty = Empty= True
' 非Empty> Empty= True
' Empty< 非Empty=False
'
' @param origin 需要比较的数组 (下标从 0 开始)
' @param size 需要进行比较的数据数量
' @param v 参与比较的数据
' @return IDFSeries 来保存比较结果为 true 的 数据
Public Function IDFDataTypeHandler_geToSeriesForArray(ByRef origin As Variant, ByRef size As Long, ByRef v As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=DF_DataType.DF_BOOLEAN
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_geToSeriesForArray = innerSeries

    ' 2. 如果 v 是 Empty，则单独计算
    Dim i As Long
    If IsEmpty(v) Then
        For i = 0 To size - 1
            ' 非Empty> Empty= True
            ' Empty = Empty= True
            result.appendData origin(i)
        Next

        Exit Function
    End If

    ' 3. 无论 v 是什么内容，将 v 转换成 boolean
    Dim booleanVal As Boolean
    booleanVal = IDFDataTypeHandler_normalize(v)

    ' 4. 遍历数据并比较
    Dim temp As Variant
    For i = 0 To size - 1
        temp = origin(i)
        If IsEmpty(temp) Then
            ' noop
        ElseIf temp = False And booleanVal = True Then
            ' False < True = False
            ' noop
        Else
            result.appendData temp
        End If
    Next
End Function

' 对数组的每一个元素和指定数据进行比较，返回一个同类型的 series，来保存比较结果为 true 的 数据
' <= 运算
' True > False = False
' False < True = True
' True = True  = True
' False = False= True
' Empty = Empty= True
' 非Empty> Empty= False
' Empty< 非Empty= True
'
' @param origin 需要比较的数组 (下标从 0 开始)
' @param size 需要进行比较的数据数量
' @param v 参与比较的数据
' @return IDFSeries 来保存比较结果为 true 的 数据
Public Function IDFDataTypeHandler_leToSeriesForArray(ByRef origin As Variant, ByRef size As Long, ByRef v As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=DF_DataType.DF_BOOLEAN
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_leToSeriesForArray = innerSeries

    ' 2. 如果 v 是 Empty，则单独计算
    Dim i As Long
    Dim temp As Variant
    If IsEmpty(v) Then
        For i = 0 To size - 1
            temp = origin(i)
            ' Empty = Empty= True
            ' 非Empty> Empty= False
            If IsEmpty(temp) Then
                result.appendEmpty
            End If
        Next

        Exit Function
    End If

    ' 3. 无论 v 是什么内容，将 v 转换成 boolean
    Dim booleanVal As Boolean
    booleanVal = IDFDataTypeHandler_normalize(v)

    ' 4. 遍历数据并比较
    For i = 0 To size - 1
        temp = origin(i)
        If IsEmpty(temp) Then
            ' Empty< 非Empty= True
            result.appendEmpty
        ElseIf origin(i) = True And booleanVal = False Then
            ' True > False = False
            ' noop
        Else
            result.appendData temp
        End If
    Next
End Function

' 对数组的每一个元素和指定数据进行比较，返回一个同类型的 series，来保存比较结果为 true 的 数据
' in() 运算
'
' True = True  = True
' False = False= True
' Empty = Empty= True
' Other        = False
'
' @param origin 需要比较的数组 (下标从 0 开始)
' @param size 需要进行比较的数据数量
' @param vs 参与比较的数据数组
' @return IDFSeries 来保存比较结果为 true 的 数据
Public Function IDFDataTypeHandler_inValsToSeriesForArray(ByRef origin As Variant, ByRef size As Long, ByRef vs As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=DF_DataType.DF_BOOLEAN
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_inValsToSeriesForArray = innerSeries

    ' 2. 将所有 vs 转换成 Boolean 或 Empty
    Dim vsMin As Integer
    Dim vsMax As Integer
    vsMin = LBound(vs)
    vsMax = UBound(vs)

    Dim realVs() As Variant
    Dim realVsMax As Integer
    realVsMax = vsMax - vsMin
    ReDim realVs(0 To realVsMax) As Variant

    For i = 0 To realVsMax
        realVs(i) = IDFDataTypeHandler_normalize(vs(vsMin + i))
    Next

    ' 3. 进行比较
    Dim j As Integer
    Dim temp As Variant
    For i = 0 To size - 1
        temp = origin(i)
        If IsEmpty(temp) Then
            ' Empty = Empty= True
            For j = 0 To realVsMax
                If IsEmpty(realVs(i)) Then
                    result.appendEmpty
                    Exit For
                End If
            Next

            ' 如果没有在 vs 中找到 Empty 数据，则忽略
        Else
            ' True = True  = True
            ' False = False= True
            For j = 0 To realVsMax
                If temp = realVs(i) Then
                    result.appendData temp
                    Exit For
                End If
            Next

            ' 如果没有在 vs 中找相等的数据，则忽略
        End If
    Next
End Function

' 对数组的每一个元素和指定数据进行比较，返回一个同类型的 series，来保存比较结果为 true 的 数据
' between 运算
'
' @param origin 需要比较的数组 (下标从 0 开始)
' @param size 需要进行比较的数据数量
' @param left 参与比较的左边界数据
' @param right 参与比较的右边界数据
' @return IDFSeries 来保存比较结果为 true 的 数据
Public Function IDFDataTypeHandler_betweenToSeriesForArray(ByRef origin As Variant, ByRef size As Long, ByRef left As Variant, ByRef right As Variant) As IDFSeries

    ' 1. 将所有左右两值转换成 Boolean 或 Empty
    Dim realLeft As Variant
    Dim realRight As Variant
    realLeft = IDFDataTypeHandler_normalize(left)
    realRight = IDFDataTypeHandler_normalize(right)

    ' 2. 检查左右值的关系
    ' 2.1 left = right, 降级成: [=]运算
    If realLeft = realRight Then
        Set IDFDataTypeHandler_betweenToSeriesForArray = IDFDataTypeHandler_eqToSeriesForArray(origin, size, realLeft)
        Exit Function
    End If

    '----------------------------------------------------------
    '----------------------------------------------------------
    '----------------------------------------------------------
    ' 剩余情况需要初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=DF_DataType.DF_BOOLEAN
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_betweenToSeriesForArray = innerSeries

    ' 2.2 left < right
    '     可能的情况:
    '      empty < False
    '      empty < True
    '      False < True
    Dim i As Long
    Dim temp As Variant
    If IsEmpty(realLeft) Then
        If realRight = False Then
            ' 2.2.1 empty < False
            ' VVVVV
            ' empty <= elem <= False
            ' VVVVV
            ' elem = Empty Or elem = False ===> True; Other ===> False
            For i = 0 To size - 1
                temp = origin(i)
                If IsEmpty(temp) Then
                    result.appendEmpty
                ElseIf temp = False Then
                    result.appendData temp
                End If
            Next
        Else
            ' 2.2.2 empty < True
            ' VVVVV
            ' empty <= elem <= True
            ' VVVVV
            ' Empty, True, False ===> True; 这种情况下，不存在 False 的情况，全部都是 True
            For i = 0 To size - 1
                result.appendData origin(i)
            Next
        End If
    ElseIf realLeft = False And realRight = True Then
        ' 2.2.3 False < True
        ' VVVVV
        ' False <= elem <= True
        ' VVVVV
        ' Empty ==> False; True, False ===> True
        For i = 0 To size - 1
            temp = origin(i)
            If Not IsEmpty(temp) Then
                result.appendData temp
            End If
        Next

    'Else
        ' 2.3 left > right, 全部返回 False，不保存任何数据
        '     False > Empty
        '     True > Empty
        '     True > False
    End If

End Function

'=========================================
' 对 Series 的数据做比较，并生成 IDFSeries 来保存结果为 true 的 数据
'=========================================
' 对 Series 的每一个元素和指定数据进行比较，返回一个同类型的 series，来保存比较结果为 true 的 数据
' = 运算
' True = True  = True
' False = False= True
' Empty = Empty= True
' Other        = False
'
' @param origin 需要比较的 Series
' @param v 参与比较的数据
' @return IDFSeries 来保存比较结果为 true 的 数据
Public Function IDFDataTypeHandler_eqToSeriesForSeries(ByRef origin As IDFSeries, ByRef v As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=DF_DataType.DF_BOOLEAN
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_eqToSeriesForSeries = innerSeries

    ' 2. 如果 v 是 Empty，则单独进行检查
    Dim i As Long
    If IsEmpty(v) Then
        For i = 0 To origin.Size - 1
            If IsEmpty(origin.unsafeGetData(i)) Then
                result.appendEmpty
            End If
        Next

        Exit Function
    End If

    ' 3. 无论 v 是什么内容，将 v 转换成 boolean
    Dim booleanVal As Boolean
    booleanVal = IDFDataTypeHandler_normalize(v)

    ' 4. 遍历数据并比较
    Dim temp As Variant
    For i = 0 To origin.Size - 1
        temp = origin.unsafeGetData(i)
        If Not IsEmpty(temp) Then
            result.appendData temp
        End If
    Next
End Function

' 对 Series 的每一个元素和指定数据进行比较，返回一个同类型的 series，来保存比较结果为 true 的 数据
' != 运算
' True = True  = False
' False = False= False
' Empty = Empty= False
' Other        = True
'
' @param origin 需要比较的 Series
' @param v 参与比较的数据
' @return IDFSeries 来保存比较结果为 true 的 数据
Public Function IDFDataTypeHandler_neToSeriesForSeries(ByRef origin As IDFSeries, ByRef v As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=DF_DataType.DF_BOOLEAN
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_neToSeriesForSeries = innerSeries

    ' 2. 如果 v 是 Empty，则单独进行检查
    Dim i As Long
    Dim temp As Variant
    If IsEmpty(v) Then
        For i = 0 To origin.Size - 1
            temp = origin.unsafeGetData(i)
            If Not IsEmpty(temp) Then
                result.appendData temp
            End If
        Next

        Exit Function
    End If

    ' 3. 无论 v 是什么内容，将 v 转换成 boolean
    Dim booleanVal As Boolean
    booleanVal = IDFDataTypeHandler_normalize(v)

    ' 4. 遍历数据并比较
    For i = 0 To origin.Size - 1
        temp = origin.unsafeGetData(i)
        If temp <> booleanVal Then
            result.appendData temp
        End If
    Next
End Function

' 对 Series 的每一个元素和指定数据进行比较，返回一个同类型的 series，来保存比较结果为 true 的 数据
' > 运算
' True > False    = True
' 非Empty > Empty = True
' Empty < 非Empty = False
' Other           = False
'
' @param origin 需要比较的 Series
' @param v 参与比较的数据
' @return IDFSeries 来保存比较结果为 true 的 数据
Public Function IDFDataTypeHandler_gtToSeriesForSeries(ByRef origin As IDFSeries, ByRef v As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=DF_DataType.DF_BOOLEAN
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_gtToSeriesForSeries = innerSeries

    ' 2. 如果 v 是 Empty，则单独计算
    Dim i As Long
    Dim temp As Variant
    If IsEmpty(v) Then
        For i = 0 To origin.Size - 1
            temp = origin.unsafeGetData(i)
            ' 非Empty > Empty = True
            If Not IsEmpty(temp) Then
                result.appendData temp
            End If
        Next

        Exit Function
    End If

    ' 3. 无论 v 是什么内容，将 v 转换成 boolean
    Dim booleanVal As Boolean
    booleanVal = IDFDataTypeHandler_normalize(v)

    ' 4. 遍历数据并比较
    ' True > False    = True
    If booleanVal = False Then
        For i = 0 To origin.Size - 1
            temp = origin.unsafeGetData(i)
            If temp = True Then
                result.appendData temp
            End If
        Next
    End If
    ' booleanVal = True 不作处理，返回空数据对象
End Function

' 对 Series 的每一个元素和指定数据进行比较，返回一个同类型的 series，来保存比较结果为 true 的 数据
' < 运算
' False > True    = True
' Empty < 非Empty = True
' 非Empty > Empty = False
' Empty = Empty   = False
' Other           = False
'
' @param origin 需要比较的 Series
' @param v 参与比较的数据
' @return IDFSeries 来保存比较结果为 true 的 数据
Public Function IDFDataTypeHandler_ltToSeriesForSeries(ByRef origin As IDFSeries, ByRef v As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=DF_DataType.DF_BOOLEAN
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_ltToSeriesForSeries = innerSeries

    ' 2. 如果 v 是 Empty，则单独计算
    Dim i As Long
    If IsEmpty(v) Then
        ' Empty = Empty ==> False; 非Empty > Empty ==> False
        ' 全部都是 False，不保存任何数据
        Exit Function
    End If

    ' 3. 无论 v 是什么内容，将 v 转换成 boolean
    Dim booleanVal As Boolean
    booleanVal = IDFDataTypeHandler_normalize(v)

    ' 4. 遍历数据并比较
    Dim temp As Variant
    For i = 0 To origin.Size - 1
        temp = origin.unsafeGetData(i)
        If IsEmpty(temp) Then
            result.appendEmpty
        ElseIf temp = False And booleanVal = True Then
            result.appendData temp
        End If
    Next
End Function

' 对 Series 的每一个元素和指定数据进行比较，返回一个同类型的 series，来保存比较结果为 true 的 数据
' >= 运算
' True > False = True
' True = True  = True
' False = False= True
' False < True = False
' Empty = Empty= True
' 非Empty> Empty= True
' Empty< 非Empty=False
'
' @param origin 需要比较的 Series
' @param v 参与比较的数据
' @return IDFSeries 来保存比较结果为 true 的 数据
Public Function IDFDataTypeHandler_geToSeriesForSeries(ByRef origin As IDFSeries, ByRef v As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=DF_DataType.DF_BOOLEAN
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_geToSeriesForSeries = innerSeries

    ' 2. 如果 v 是 Empty，则单独计算
    Dim i As Long
    If IsEmpty(v) Then
        For i = 0 To origin.Size - 1
            ' 非Empty> Empty= True
            ' Empty = Empty= True
            result.appendData origin.unsafeGetData(i)
        Next

        Exit Function
    End If

    ' 3. 无论 v 是什么内容，将 v 转换成 boolean
    Dim booleanVal As Boolean
    booleanVal = IDFDataTypeHandler_normalize(v)

    ' 4. 遍历数据并比较
    Dim temp As Variant
    For i = 0 To origin.Size - 1
        temp = origin.unsafeGetData(i)
        If IsEmpty(temp) Then
            ' noop
        ElseIf temp = False And booleanVal = True Then
            ' False < True = False
            ' noop
        Else
            result.appendData temp
        End If
    Next
End Function

' 对 Series 的每一个元素和指定数据进行比较，返回一个同类型的 series，来保存比较结果为 true 的 数据
' <= 运算
' True > False = False
' False < True = True
' True = True  = True
' False = False= True
' Empty = Empty= True
' 非Empty> Empty= False
' Empty< 非Empty= True
'
' @param origin 需要比较的 Series
' @param v 参与比较的数据
' @return IDFSeries 来保存比较结果为 true 的 数据
Public Function IDFDataTypeHandler_leToSeriesForSeries(ByRef origin As IDFSeries, ByRef v As Variant) As IDFSeries
   ' 1. 初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=DF_DataType.DF_BOOLEAN
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_leToSeriesForSeries = innerSeries

    ' 2. 如果 v 是 Empty，则单独计算
    Dim i As Long
    If IsEmpty(v) Then
        For i = 0 To origin.Size - 1
            ' Empty = Empty= True
            ' 非Empty> Empty= False
            If IsEmpty(origin.unsafeGetData(i)) Then
                result.appendEmpty
            End If
        Next

        Exit Function
    End If

    ' 3. 无论 v 是什么内容，将 v 转换成 boolean
    Dim booleanVal As Boolean
    booleanVal = IDFDataTypeHandler_normalize(v)

    ' 4. 遍历数据并比较
    Dim temp As Variant
    For i = 0 To origin.Size - 1
        temp = origin.unsafeGetData(i)
        If IsEmpty(temp) Then
            ' Empty< 非Empty= True
            result.appendEmpty
        ElseIf temp = True And booleanVal = False Then
            ' True > False = False
            ' noop
        Else
            result.appendData temp
        End If
    Next
End Function

' 对 Series 的每一个元素和指定数据进行比较，返回一个同类型的 series，来保存比较结果为 true 的 数据
' in() 运算
'
' @param origin 需要比较的 Series
' @param vs 参与比较的数据数组
' @return IDFSeries 来保存比较结果为 true 的 数据
Public Function IDFDataTypeHandler_inValsToSeriesForSeries(ByRef origin As IDFSeries, ByRef vs As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=DF_DataType.DF_BOOLEAN
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_inValsToSeriesForSeries = innerSeries

    ' 2. 将所有 vs 转换成 Boolean 或 Empty
    Dim vsMin As Integer
    Dim vsMax As Integer
    vsMin = LBound(vs)
    vsMax = UBound(vs)

    Dim realVs() As Variant
    Dim realVsMax As Integer
    realVsMax = vsMax - vsMin
    ReDim realVs(0 To realVsMax) As Variant

    For i = 0 To realVsMax
        realVs(i) = IDFDataTypeHandler_normalize(vs(vsMin + i))
    Next

    ' 3. 进行比较
    Dim j As Integer
    Dim temp As Variant
    For i = 0 To origin.Size - 1
        temp = origin.unsafeGetData(i)
        If IsEmpty(temp) Then
            ' Empty = Empty= True
            For j = 0 To realVsMax
                If IsEmpty(realVs(i)) Then
                    result.appendEmpty
                    Exit For
                End If
            Next

            ' 如果没有在 vs 中找到 Empty 数据，则忽略
        Else
            ' True = True  = True
            ' False = False= True
            For j = 0 To realVsMax
                If temp = realVs(i) Then
                    result.appendData temp
                    Exit For
                End If
            Next

            ' 如果没有在 vs 中找相等的数据，则忽略
        End If
    Next
End Function

' 对 Series 的每一个元素和指定数据进行比较，返回一个同类型的 series，来保存比较结果为 true 的 数据
' between 运算
'
' @param origin 需要比较的 Series
' @param left 参与比较的左边界数据
' @param right 参与比较的右边界数据
' @return IDFSeries 来保存比较结果为 true 的 数据
Public Function IDFDataTypeHandler_betweenToSeriesForSeries(ByRef origin As IDFSeries, ByRef left As Variant, ByRef right As Variant) As IDFSeries

    ' 1. 将所有左右两值转换成 Boolean 或 Empty
    Dim realLeft As Variant
    Dim realRight As Variant
    realLeft = IDFDataTypeHandler_normalize(left)
    realRight = IDFDataTypeHandler_normalize(right)

    ' 2. 检查左右值的关系
    ' 2.1 left = right, 降级成: [=]运算
    If realLeft = realRight Then
        Set IDFDataTypeHandler_betweenToSeriesForSeries = IDFDataTypeHandler_eqToSeriesForSeries(origin, realLeft)
        Exit Function
    End If

    '----------------------------------------------------------
    '----------------------------------------------------------
    '----------------------------------------------------------
    ' 剩余情况需要初始化结果对象
    Dim innerSeries As DFSeriesInner
    Set innerSeries = New DFSeriesInner
    innerSeries.Init dType:=DF_DataType.DF_BOOLEAN
    Dim result As IDFSeries
    Set result = innerSeries

    Set IDFDataTypeHandler_betweenToSeriesForSeries = innerSeries


    ' 2.2 left < right
    '     可能的情况:
    '      empty < False
    '      empty < True
    '      False < True
    Dim i As Long
    Dim temp As Variant
    If IsEmpty(realLeft) Then
        If realRight = False Then
            ' 2.2.1 empty < False
            ' VVVVV
            ' empty <= elem <= False
            ' VVVVV
            ' elem = Empty Or elem = False ===> True; Other ===> False
            For i = 0 To origin.Size - 1
                temp = origin.unsafeGetData(i)
                If IsEmpty(temp) Then
                    result.appendEmpty
                ElseIf temp = False Then
                    result.appendData temp
                End If
            Next
        Else
            ' 2.2.2 empty < True
            ' VVVVV
            ' empty <= elem <= True
            ' VVVVV
            ' Empty, True, False ===> True; 这种情况下，不存在 False 的情况，全部都是 True
            For i = 0 To origin.Size - 1
                result.appendData origin.unsafeGetData(i)
            Next
        End If
    ElseIf realLeft = False And realRight = True Then
        ' 2.2.3 False < True
        ' VVVVV
        ' False <= elem <= True
        ' VVVVV
        ' Empty ==> False; True, False ===> True
        For i = 0 To origin.Size - 1
            temp = origin.unsafeGetData(i)
            If Not IsEmpty(temp) Then
                result.appendData temp
            End If
        Next

    'Else
        ' 2.3 left > right, 全部返回 False
        '     False > Empty
        '     True > Empty
        '     True > False
    '    For i = 0 To origin.Size - 1
    '        result.appendData False
    '    Next
    End If

End Function

'=========================================
' 对 Series 的数据做比较，并生成包含结果为 true 的数据切片 Series
'=========================================
' 对 Series 的每一个元素和指定数据进行比较，返回一个同类型的 series 切片，来保存比较结果为 true 的数据的引用
' = 运算
' True = True  = True
' False = False= True
' Empty = Empty= True
' Other        = False
'
' @param origin 需要比较的 Series
' @param v 参与比较的数据
' @return IDFSeries 切片，来保存比较结果为 true 的数据的引用
Public Function IDFDataTypeHandler_eqToSliceForSeries(ByRef origin As IDFSeries, ByRef v As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim dfSlice As DFSeriesSlice
    Set dfSlice = New DFSeriesSlice
    dfSlice.InitEmptyRef origin

    Set IDFDataTypeHandler_eqToSliceForSeries = dfSlice

    ' 2. 如果 v 是 Empty，则单独进行检查
    Dim i As Long
    If IsEmpty(v) Then
        For i = 0 To origin.Size - 1
            If IsEmpty(origin.unsafeGetData(i)) Then
                dfSlice.appendRef i
            End If
        Next

        Exit Function
    End If

    ' 3. 无论 v 是什么内容，将 v 转换成 boolean
    Dim booleanVal As Boolean
    booleanVal = IDFDataTypeHandler_normalize(v)

    ' 4. 遍历数据并比较
    For i = 0 To origin.Size - 1
        If Not IsEmpty(origin.unsafeGetData(i)) Then
            dfSlice.appendRef i
        End If
    Next
End Function

' 对 Series 的每一个元素和指定数据进行比较，返回一个同类型的 series 切片，来保存比较结果为 true 的数据的引用
' != 运算
' True = True  = False
' False = False= False
' Empty = Empty= False
' Other        = True
'
' @param origin 需要比较的 Series
' @param v 参与比较的数据
' @return IDFSeries 切片，来保存比较结果为 true 的数据的引用
Public Function IDFDataTypeHandler_neToSliceForSeries(ByRef origin As IDFSeries, ByRef v As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim dfSlice As DFSeriesSlice
    Set dfSlice = New DFSeriesSlice
    dfSlice.InitEmptyRef origin

    Set IDFDataTypeHandler_neToSliceForSeries = dfSlice

    ' 2. 如果 v 是 Empty，则单独进行检查
    Dim i As Long
    If IsEmpty(v) Then
        For i = 0 To origin.Size - 1
            If Not IsEmpty(origin.unsafeGetData(i)) Then
                dfSlice.appendRef i
            End If
        Next

        Exit Function
    End If

    ' 3. 无论 v 是什么内容，将 v 转换成 boolean
    Dim booleanVal As Boolean
    booleanVal = IDFDataTypeHandler_normalize(v)

    ' 4. 遍历数据并比较
    For i = 0 To origin.Size - 1
        If origin.unsafeGetData(i) <> booleanVal Then
            dfSlice.appendRef i
        End If
    Next
End Function

' 对 Series 的每一个元素和指定数据进行比较，返回一个同类型的 series 切片，来保存比较结果为 true 的数据的引用
' > 运算
' True > False    = True
' 非Empty > Empty = True
' Empty < 非Empty = False
' Other           = False
'
' @param origin 需要比较的 Series
' @param v 参与比较的数据
' @return IDFSeries 切片，来保存比较结果为 true 的数据的引用
Public Function IDFDataTypeHandler_gtToSliceForSeries(ByRef origin As IDFSeries, ByRef v As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim dfSlice As DFSeriesSlice
    Set dfSlice = New DFSeriesSlice
    dfSlice.InitEmptyRef origin

    Set IDFDataTypeHandler_gtToSliceForSeries = dfSlice

    ' 2. 如果 v 是 Empty，则单独计算
    Dim i As Long
    If IsEmpty(v) Then
        For i = 0 To origin.Size - 1
            ' 非Empty > Empty = True
            If Not IsEmpty(origin.unsafeGetData(i)) Then
                dfSlice.appendRef i
            End If
        Next

        Exit Function
    End If

    ' 3. 无论 v 是什么内容，将 v 转换成 boolean
    Dim booleanVal As Boolean
    booleanVal = IDFDataTypeHandler_normalize(v)

    ' 4. 遍历数据并比较
    ' True > False    = True
    If booleanVal = False Then
        For i = 0 To origin.Size - 1
            If origin.unsafeGetData(i) = True Then
                dfSlice.appendRef i
            End If
        Next
    End If
    ' booleanVal = True 不作处理，返回空数据对象
End Function

' 对 Series 的每一个元素和指定数据进行比较，返回一个同类型的 series 切片，来保存比较结果为 true 的数据的引用
' < 运算
' False > True    = True
' Empty < 非Empty = True
' 非Empty > Empty = False
' Other           = False
'
' @param origin 需要比较的 Series
' @param v 参与比较的数据
' @return IDFSeries 切片，来保存比较结果为 true 的数据的引用
Public Function IDFDataTypeHandler_ltToSliceForSeries(ByRef origin As IDFSeries, ByRef v As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim dfSlice As DFSeriesSlice
    Set dfSlice = New DFSeriesSlice
    dfSlice.InitEmptyRef origin

    Set IDFDataTypeHandler_ltToSliceForSeries = dfSlice

    ' 2. 如果 v 是 Empty，则单独计算
    Dim i As Long
    If IsEmpty(v) Then
        For i = 0 To origin.Size - 1
            ' 非Empty > Empty = False
            If IsEmpty(origin.unsafeGetData(i)) Then
                dfSlice.appendRef i
            End If
        Next

        Exit Function
    End If

    ' 3. 无论 v 是什么内容，将 v 转换成 boolean
    Dim booleanVal As Boolean
    booleanVal = IDFDataTypeHandler_normalize(v)

    ' 4. 遍历数据并比较
    For i = 0 To origin.Size - 1
        temp = origin.unsafeGetData(i)
        If IsEmpty(temp) Then
            dfSlice.appendRef i
        ElseIf temp = False And booleanVal = True Then
            dfSlice.appendRef i
        End If
    Next
End Function

' 对 Series 的每一个元素和指定数据进行比较，返回一个同类型的 series 切片，来保存比较结果为 true 的数据的引用
' >= 运算
' True > False = True
' True = True  = True
' False = False= True
' False < True = False
' Empty = Empty= True
' 非Empty> Empty= True
' Empty< 非Empty=False
'
' @param origin 需要比较的 Series
' @param v 参与比较的数据
' @return IDFSeries 切片，来保存比较结果为 true 的数据的引用
Public Function IDFDataTypeHandler_geToSliceForSeries(ByRef origin As IDFSeries, ByRef v As Variant) As IDFSeries
    ' 1. 创建结果对象
    Dim dfSlice As DFSeriesSlice
    Set dfSlice = New DFSeriesSlice
    Set IDFDataTypeHandler_geToSliceForSeries = dfSlice


    ' 2. 如果 v 是 Empty，则单独计算
    Dim i As Long
    If IsEmpty(v) Then
        ' 非Empty> Empty= True
        ' Empty = Empty= True
        ' 全部数据都符合规则
        dfSlice.Init origin

        Exit Function
    End If

    ' 3. 初始化结果对象
    dfSlice.InitEmptyRef origin

    ' 4. 无论 v 是什么内容，将 v 转换成 boolean
    Dim booleanVal As Boolean
    booleanVal = IDFDataTypeHandler_normalize(v)

    ' 5. 遍历数据并比较
    Dim temp As Variant
    For i = 0 To origin.Size - 1
        temp = origin.unsafeGetData(i)
        If IsEmpty(temp) Then
            ' noop
        ElseIf temp = False And booleanVal = True Then
            ' False < True = False
            ' noop
        Else
            dfSlice.appendRef i
        End If
    Next
End Function

' 对 Series 的每一个元素和指定数据进行比较，返回一个同类型的 series 切片，来保存比较结果为 true 的数据的引用
' <= 运算
' True > False = False
' False < True = True
' True = True  = True
' False = False= True
' Empty = Empty= True
' 非Empty> Empty= False
' Empty< 非Empty= True
'
' @param origin 需要比较的 Series
' @param v 参与比较的数据
' @return IDFSeries 切片，来保存比较结果为 true 的数据的引用
Public Function IDFDataTypeHandler_leToSliceForSeries(ByRef origin As IDFSeries, ByRef v As Variant) As IDFSeries
   ' 1. 初始化结果对象
    Dim dfSlice As DFSeriesSlice
    Set dfSlice = New DFSeriesSlice
    dfSlice.InitEmptyRef origin

    Set IDFDataTypeHandler_leToSliceForSeries = dfSlice

    ' 2. 如果 v 是 Empty，则单独计算
    Dim i As Long
    If IsEmpty(v) Then
        For i = 0 To origin.Size - 1
            ' Empty = Empty= True
            ' 非Empty> Empty= False
            If IsEmpty(origin.unsafeGetData(i)) Then
                dfSlice.appendRef i
            End If
        Next

        Exit Function
    End If

    ' 3. 无论 v 是什么内容，将 v 转换成 boolean
    Dim booleanVal As Boolean
    booleanVal = IDFDataTypeHandler_normalize(v)

    ' 4. 遍历数据并比较
    Dim temp As Variant
    For i = 0 To origin.Size - 1
        temp = origin.unsafeGetData(i)
        If IsEmpty(temp) Then
            ' Empty< 非Empty= True
            dfSlice.appendRef i
        ElseIf temp = True And booleanVal = False Then
            ' True > False = False
            ' noop
        Else
            dfSlice.appendRef i
        End If
    Next
End Function

' 对 Series 的每一个元素和指定数据进行比较，返回一个同类型的 series 切片，来保存比较结果为 true 的数据的引用
' in() 运算
'
' @param origin 需要比较的 Series
' @param vs 参与比较的数据数组
' @return IDFSeries 切片，来保存比较结果为 true 的数据的引用
Public Function IDFDataTypeHandler_inValsToSliceForSeries(ByRef origin As IDFSeries, ByRef vs As Variant) As IDFSeries
    ' 1. 初始化结果对象
    Dim dfSlice As DFSeriesSlice
    Set dfSlice = New DFSeriesSlice
    dfSlice.InitEmptyRef origin

    Set IDFDataTypeHandler_inValsToSliceForSeries = dfSlice

    ' 2. 将所有 vs 转换成 Boolean 或 Empty
    Dim vsMin As Integer
    Dim vsMax As Integer
    vsMin = LBound(vs)
    vsMax = UBound(vs)

    Dim realVs() As Variant
    Dim realVsMax As Integer
    realVsMax = vsMax - vsMin
    ReDim realVs(0 To realVsMax) As Variant

    For i = 0 To realVsMax
        realVs(i) = IDFDataTypeHandler_normalize(vs(vsMin + i))
    Next

    ' 3. 进行比较
    Dim j As Integer
    Dim temp As Variant
    For i = 0 To origin.Size - 1
        temp = origin.unsafeGetData(i)
        If IsEmpty(temp) Then
            ' Empty = Empty= True
            For j = 0 To realVsMax
                If IsEmpty(realVs(i)) Then
                    dfSlice.appendRef i
                    Exit For
                End If
            Next

            ' 如果没有在 vs 中找到 Empty 数据，则忽略
        Else
            ' True = True  = True
            ' False = False= True
            For j = 0 To realVsMax
                If temp = realVs(i) Then
                    dfSlice.appendRef i
                    Exit For
                End If
            Next

            ' 如果没有在 vs 中找相等的数据，则忽略
        End If
    Next
End Function

' 对 Series 的每一个元素和指定数据进行比较，返回一个同类型的 series 切片，来保存比较结果为 true 的数据的引用
' between 运算
'
' @param origin 需要比较的 Series
' @param left 参与比较的左边界数据
' @param right 参与比较的右边界数据
' @return IDFSeries 切片，来保存比较结果为 true 的数据的引用
Public Function IDFDataTypeHandler_betweenToSliceForSeries(ByRef origin As IDFSeries, ByRef left As Variant, ByRef right As Variant) As IDFSeries

    ' 1. 将所有左右两值转换成 Boolean 或 Empty
    Dim realLeft As Variant
    Dim realRight As Variant
    realLeft = IDFDataTypeHandler_normalize(left)
    realRight = IDFDataTypeHandler_normalize(right)

    ' 2. 检查左右值的关系
    ' 2.1 left = right, 降级成: [=]运算
    If realLeft = realRight Then
        Set IDFDataTypeHandler_betweenToSliceForSeries = IDFDataTypeHandler_eqToSliceForSeries(origin, realLeft)
        Exit Function
    End If

    '----------------------------------------------------------
    '----------------------------------------------------------
    '----------------------------------------------------------
    ' 剩余情况需要初始化结果对象
    Dim dfSlice As DFSeriesSlice
    Set dfSlice = New DFSeriesSlice
    dfSlice.InitEmptyRef origin

    Set IDFDataTypeHandler_betweenToSliceForSeries = dfSlice

    ' 2.2 left < right
    '     可能的情况:
    '      empty < False
    '      empty < True
    '      False < True
    Dim i As Long
    Dim temp As Variant
    If IsEmpty(realLeft) Then
        If realRight = False Then
            ' 2.2.1 empty < False
            ' VVVVV
            ' empty <= elem <= False
            ' VVVVV
            ' elem = Empty Or elem = False ===> True; Other ===> False
            For i = 0 To origin.Size - 1
                temp = origin.unsafeGetData(i)
                If IsEmpty(temp) Then
                    dfSlice.appendRef i
                ElseIf temp = False Then
                    dfSlice.appendRef i
                End If
            Next
        Else
            ' 2.2.2 empty < True
            ' VVVVV
            ' empty <= elem <= True
            ' VVVVV
            ' Empty, True, False ===> True; 这种情况下，不存在 False 的情况，全部都是 True
            For i = 0 To origin.Size - 1
                dfSlice.appendRef i
            Next
        End If
    ElseIf realLeft = False And realRight = True Then
        ' 2.2.3 False < True
        ' VVVVV
        ' False <= elem <= True
        ' VVVVV
        ' Empty ==> False; True, False ===> True
        For i = 0 To origin.Size - 1
            If Not IsEmpty(origin.unsafeGetData(i)) Then
                dfSlice.appendRef i
            End If
        Next

    'Else
        ' 2.3 left > right, 全部返回 False
        '     False > Empty
        '     True > Empty
        '     True > False
    '    For i = 0 To origin.Size - 1
    '        result.appendData False
    '    Next
    End If

End Function